﻿layui.use(['upload', 'element', 'layer', 'table', 'dropdown', 'form', 'laydate'], function () {
    var $ = layui.jquery
        , upload = layui.upload
        , element = layui.element
        , layer = layui.layer
        , dropdown = layui.dropdown
        , laydate = layui.laydate
        , form = layui.form
        , table = layui.table;

   
    //var Jbxxid = "uuujmj-123123-11";
    //var Jbxxid = form.val("formBasicInfo").jbxxid;
    //var Jbxxid = $("#jbxxid").val();
    abc = $("#jbxxid").val() === '' ? '' : '?Jbxxid=' + $("#jbxxid").val();
    //招录信息保存
    layui.use('table', function () {
        table.render({
            elem: '#tablezlxx'
            , url: '../Zlxxes/ShowZlxx' + abc //数据接口
            , page: true //开启分页
            , toolbar: '#toolbarZlxx' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , cols: [[ //表头
                { field: 'lyscrouce', title: '录用来源', width: 125, minWidth: 125 }
                , { field: 'remark', title: '备注', width: 125, minWidth: 125 }
                , { field: 'rz', title: '面试人员', width: 125, minWidth: 125 }
                , { field: 'rcdjb', title: '《人才登记表》', width: 125, minWidth: 125, templet: proofPicturercdjb }
                , { field: 'msb', title: '《面试评定表》', width: 125, minWidth: 125, templet: proofPicturemsb }
                , { fixed: 'yesorno', title: '是否背景调查', width: 125, minWidth: 125, toolbar: '#yesorno'}
                , { field: 'bjdc', title: '背景调查报告', width: 137, minWidth: 137 ,templet: function (d) {

                        if (d.bjdc != null && d.bjdc != "" && d.bjdc != "[]") {
                            let str = [];

                            for (i = 0; i < d.bjdc.length; i++) {
                                if (d.bjdc[i] != "?") {
                                    str += d.bjdc[i];

                                } else {
                                    str += "\n";
                                }
                            }
                            return str;


                        }

                    } }
                , { field: 'result', title: '薪酬评定结果', width: 125, minWidth: 125, templet: function (d) {

                        if (d.result != null && d.result != "" && d.result != "[]") {
                            let str = [];

                            for (i = 0; i < d.result.length; i++) {
                                if (d.result[i] != "?") {
                                    str += d.result[i];

                                } else {
                                    str += "\n";
                                }
                            }
                            return str;
                        }

                    }  }
                , { field: 'resultBz', title: '《薪酬评定表》', width: 125, minWidth: 125, templet: proofPicturebz }
                , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#toolbarzlxx' }
            ]]
            , page: true
            , done: function (res) {
                if (res.data[0].lyscrouce != "关系推荐") {
                    $("[data-field='remark']").css('display', 'none');
                }
                if (res.data[0].bjdc == "没有背景调查") {
                    $("[data-field='bjdc']").css('display', 'none');
                    $("#yesyes").hide();
                } else {
                    $("#nono").hide();
                }
            }
        });
        table.on('toolbar(tablezlxx)', function (obj) {
            //var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;  //获取选中行数据
                    layer.alert(JSON.stringify(data));
                    break;

                case 'addZlxxData':
                    layer.open({
                        type: 1
                        , title: '录用信息'
                        , id: 'layerDemo1'//防止重复弹出
                        , area: ["80%", "70%"]
                        , content: $("#zlxxform")//form 隐藏 display none
                        , btn: '保存'
                        , btnAlign: 'c' //按钮居中
                        , shade: 0 //不显示遮罩
                        , yes: function () {
                            if ($("#demo3").val() == "") {
                                layer.msg("面试人员未填写");
                                return;
                            } else if ($("#msb").val() == "无附件") {
                                layer.alert("确定不上传附件？");

                            };
                            UpZlxx();
                            table.reload('tablezlxx', {
                                where: {
                                    "Jbxxid": $("#jbxxid").val()
                                }
                            });
                            $("#zlxxform").hide();
                            layer.closeAll();
                        },
                        cancel: function () {
                            $("#zlxxform").hide();
                        }
                    })
                    break;
            };
        });
        table.on('tool(tablezlxx)', function (obj) {
            var data = obj.data;

            if (obj.event === 'del_zlxx') {
                layer.confirm('真的删除行么', function (index) {

                    $.ajax({
                        url: "/Zlxxes/Del_zlxx",    //后台数据请求地址
                        type: "post",
                        async: false,
                        data: { "id": data.id },
                        success: function (resut) {
                            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            layer.close(index);
                            console.log(index);
                            layer.msg(resut);
                        }
                    });                   
                    layer.close(index);
                });
            }
            else if (obj.event === 'edit_zlxx') {

                $('[name="Lyscrouce"]').val(data.lyscrouce);
                $('[name="Remark"]').val(data.remark);
                $('[name="Rz"]').val(data.rz);
                $('[name="Yrbm"]').val(data.rcdjb);
                $('[name="Msb"]').val(data.msb);
                $('[name="Bjdc"]').val(data.bjdc.replace(/<br\/>/g, '\n'));
                $('[name="Result"]').val(data.result.replace(/<br\/>/g, '\n'));
                $('[name="ResultBz"]').val(data.resultBz);

                form.render('select');
                layer.open({
                    title: '编辑',
                    type: 1,
                    area: ['70%', '82%'],
                    content: $("#zlxxform")
                    , btn: '保存'
                    , btnAlign: 'c' //按钮居中
                    , shade: 0 //不显示遮罩
                    , cancel: function () {
                        $("#zlxxform").hide();
                    }, success: function () {
                        console.log(data.msb);

                        if (data.bjdc != "没有背景调查") {
                            //$(item).prop('checked', true);
                            form.val("zlxxform", {
                                "dc": "是"
                            });
                            $("#yesbjdc").show();
                            $("textarea[name=Bjdc]").val(data.bjdc.replace(/<br\/>/g, '\n'));
                            //重新渲染
                            layui.use('form', function () {
                                var form = layui.form;
                                form.render();
                            });
                        } else {
                            form.val("zlxxform", {
                                "dc": "否"
                            });
                            $("#yesbjdc").hide();

                            //重新渲染
                            layui.use('form', function () {
                                var form = layui.form;
                                form.render();
                            });
                        }
                    } ,
                    yes: function (index) {
                        if (document.getElementById('msb').value == "" || document.getElementById('msb').value==null) {
                            document.getElementById('msb').value = "无附件";

                        } else if(document.getElementById('ResultBz').value == "" || document.getElementById('ResultBz').value == null) {
                            document.getElementById('ResultBz').value = "无附件";

                        } else if (document.getElementById('rcdjb').value == "" || document.getElementById('rcdjb').value == null) {
                            document.getElementById('rcdjb').value = "无附件";

                        }
                        $.ajax({
                            url: "/Zlxxes/Del_zlxx",    //后台数据请求地址
                            type: "post",
                            async: false,
                            data: { "id": data.id },
                            success: function (resut) {
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                layer.close(index);
                                console.log(index);
                                layer.msg(resut);
                            }
                        });
                        UpZlxx();
                        table.reload('tablezlxx', {
                            where: {
                                "Jbxxid": $("#jbxxid").val()
                            }
                        });

                        $("#zlxxform").hide();
                        layer.close(index);
                    }
                });                
            };
        });
        
    });
    //人才登记表
    var uploadListIns = upload.render({
        elem: '#testrcdjbList'
        , elemList: $('#demoListrcdjb') //列表元素对象
        , url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        , accept: 'file'
        , multiple: true
        , number: 3
        , auto: false
        , bindAction: '#testrcdjbListAction'
        , choose: function (obj) {
            var that = this;
            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
            //读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr name="" id="upload-' + index + '">'
                    , '<td><input style="border: 0;" readonly class="rcdjbname" type="text"  value="' + file.name + '"></td>'
                    //, '<td class=""fname>' + file.name + '</td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    delete files[index]; //删除对应的文件
                    tr.remove();


                    var tags = [];
                    $(".rcdjbname").each(function (i, e) {
                        tags[i] = $(this).val();

                    });
                    document.getElementById('rcdjb').value = tags.toString();


                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                });
                that.elemList.append(tr);
                element.render('progress'); //渲染新加的进度条组件
            });
        }
        , done: function (res, index, upload) { //成功的回调
            // console.log(this.files);
            var that = this;
            //if(res.code == 0){ //上传成功
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            //tds.eq(3).html(''); //清空操作
            var tags = [];
            $(".rcdjbname").each(function (i, e) {
                tags[i] = $(this).val();
            });
            document.getElementById('rcdjb').value = tags.toString();
            delete this.files[index]; //删除文件队列已经上传成功的文件
            layer.msg("上传成功");
            return;
            //}
            //this.error(index, upload);
        }
        , allDone: function (obj) { //多文件上传完毕后的状态回调
            //console.log(obj)
        }
        , error: function (index, upload) { //错误回调
            var that = this;
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
        }
        , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
            element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
        }
    });

    //面试表附件
    var uploadListIns = upload.render({
        elem: '#testmsbList'
        , elemList: $('#demoListmsb') //列表元素对象
        , url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        , accept: 'file'
        , multiple: true
        , number: 3
        , auto: false
        , bindAction: '#testmsbListAction'
        , choose: function (obj) {
            var that = this;
            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
            //读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr name="" id="upload-' + index + '">'
                    , '<td><input style="border: 0;" readonly class="fname" type="text"  value="' + file.name + '"></td>'
                    //, '<td class=""fname>' + file.name + '</td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    delete files[index]; //删除对应的文件
                    tr.remove();


                    var tags = [];
                    $(".fname").each(function (i, e) {
                        tags[i] = $(this).val();

                    });
                    document.getElementById('msb').value = tags.toString();


                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                });
                that.elemList.append(tr);
                element.render('progress'); //渲染新加的进度条组件
            });
        }
        , done: function (res, index, upload) { //成功的回调
           // console.log(this.files);
            var that = this;
            //if(res.code == 0){ //上传成功
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            //tds.eq(3).html(''); //清空操作
            var tags = [];
            $(".fname").each(function (i, e) {
                tags[i] =$(this).val();

            });
            document.getElementById('msb').value = tags.toString();
            delete this.files[index]; //删除文件队列已经上传成功的文件
            layer.msg("上传成功");
            return;
            //}
            //this.error(index, upload);
        }
        , allDone: function (obj) { //多文件上传完毕后的状态回调
            //console.log(obj)
        }
        , error: function (index, upload) { //错误回调
            var that = this;
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
        }
        , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
            element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
        }
    });

    //演示多文件列表
    var uploadListIns = upload.render({
        elem: '#testxcList'
        , elemList: $('#demoListxc') //列表元素对象
        , url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        , accept: 'file'
        , multiple: true
        , number: 3
        , auto: false
        , bindAction: '#testxcListAction'
        , choose: function (obj) {
            var that = this;
            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
            //读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr id="upload-' + index + '">'
                    , '<td><input style="border: 0;" readonly class="xcname" type="text"  value="' + file.name + '"></td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    delete files[index]; //删除对应的文件
                    tr.remove();

                    var tags = [];
                    $(".xcname").each(function (i, e) {
                        tags[i] = $(this).val();

                    });
                    document.getElementById('ResultBz').value = tags.toString();


                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                });

                that.elemList.append(tr);
                element.render('progress'); //渲染新加的进度条组件
            });
        }
        , done: function (res, index, upload) { //成功的回调
            var that = this;
            //if(res.code == 0){ //上传成功
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            //tds.eq(3).html(''); //清空操作

            var tags = [];
            $(".xcname").each(function (i, e) {
                tags[i] = $(this).val();
            });
            document.getElementById('ResultBz').value = tags.toString();
            delete this.files[index]; //删除文件队列已经上传成功的文件
            layer.msg("上传成功");
            return;
            //}


            this.error(index, upload);
        }
        , allDone: function (obj) { //多文件上传完毕后的状态回调
            //console.log(obj)
        }
        , error: function (index, upload) { //错误回调
            var that = this;
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
        }
        , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
            element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
        }
    });

    //人才测评附件
    var uploadListIns = upload.render({
        elem: '#testcpList'
        , elemList: $('#demoListcp') //列表元素对象
        , url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        , accept: 'file'
        , multiple: true
        , number: 3
        , auto: false
        , bindAction: '#testcpListAction'
        , choose: function (obj) {
            var that = this;
            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
            //读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr id="upload-' + index + '">'
                    , '<td><input style="border: 0;" readonly class="rccpname" type="text"  value="' + file.name + '"></td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    delete files[index]; //删除对应的文件
                    tr.remove();

                    var tags = [];
                    $(".rccpname").each(function (i, e) {
                        tags[i] = $(this).val();

                    });
                    document.getElementById('CpFile').value = tags.toString();


                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                });

                that.elemList.append(tr);
                element.render('progress'); //渲染新加的进度条组件
            });
        }
        , done: function (res, index, upload) { //成功的回调
            var that = this;
            //if(res.code == 0){ //上传成功
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            //tds.eq(3).html(''); //清空操作
            var tags = [];
            $(".rccpname").each(function (i, e) {
                tags[i] = $(this).val();
            });
            document.getElementById('CpFile').value = tags.toString();
            delete this.files[index]; //删除文件队列已经上传成功的文件
            layer.msg("上传成功");
            return;
            //}


            this.error(index, upload);
        }
        , allDone: function (obj) { //多文件上传完毕后的状态回调
            //console.log(obj)
        }
        , error: function (index, upload) { //错误回调
            var that = this;
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
        }
        , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
            element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
        }
    });

    //人才测评保存
    layui.use('table', function () {
        var $ = layui.jquery

        table.render({
            elem: '#testRccp'
            , url: '../Rccps/ShowRccp' + abc
           // , data: Showrccp()
            , toolbar: '#toolbarDemoRccp'
            , cols: [[
                { field: 'CpTool', width: 128, title: '测评工具', width: 125, minWidth: 125 }
                , { field: 'CpType', width: 128, title: '测评类型', width: 125, minWidth: 125 }
                , { field: 'DateTime', width: 120, title: '测评时间', width: 110, minWidth: 110 }
                , { field: 'CpResult', width: 180, title: '测评结果', width: 440, minWidth: 440, templet: function (d) {
                        if (d.CpResult != null && d.CpResult != "" && d.CpResult != "[]") {
                            let str = [];

                            for (i = 0; i < d.CpResult.length; i++) {
                                if (d.CpResult[i] != "?") {
                                    str += d.CpResult[i];

                                } else {
                                    str += "\n";
                                }
                            }
                            return str;
                        }
                        
                        }
                    }
                , { field: 'CpFile', width: 180, title: '测评报告', width: 125, minWidth: 125, templet: proofPicturecp }
                , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#toolbarrccp' }
            ]]
            , page: true
        });

        table.on('toolbar(testRccp)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;  //获取选中行数据
                    layer.alert(JSON.stringify(data));
                    break;

                case 'addRccpData':
                    layer.open({
                        type: 1
                        , title: '人才测评'
                        , id: 'layerDemo1'//防止重复弹出
                        , area: ["80%", "70%"]
                        , content: $("#rccp"),//form 隐藏 display none

                        btn: '保存'
                        , btnAlign: 'c' //按钮居中
                        , shade: 0 //不显示遮罩
                        , yes: function () {
                            if ($(".cpdate").val() == "") {
                                layer.msg("测评时间未填写");
                                return;
                            } else if ($("#cptype").val() == "") {
                                layer.msg("测评类型未填写");
                                return;
                            } else if ($("#CpFile").val() == "无附件") {
                                layer.msg("没有上传附件");
                            }

                            to();
                            UpRccp();//INSERT 
                            //console.log(16);
                            table.reload('testRccp', {
                                where: {
                                    "Jbxxid": $("#jbxxid").val()
                                }
                            });
                            layer.closeAll();
                            layer.msg("保存成功");

                        },


                        cancel: function () {


                            $("#rccp").hide()


                        },
                    })
                    break;
            };
        });
        table.on('tool(testRccp)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del_rccp') {
                layer.confirm('真的删除行么', function (index) {

                    $.ajax({
                        url: "/Rccps/Del_rccp",    //后台数据请求地址
                        type: "post",
                        async: false,
                        data: { "id": data.id },
                        success: function (resut) {
                            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            layer.close(index);
                            console.log(index);
                            layer.msg(resut);
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit_rccp') {

                if (document.getElementById('CpFile').value == "" || document.getElementById('CpFile').value == null) {
                    document.getElementById('CpFile').value = "无附件";

                }

                $('[name="CpType"]').val(data.CpType);
                $(".cpdate").val(data.DateTime);
                $('[name="CpResult"]').val(data.CpResult);
                $('[name="CpFile"]').val(data.CpFile);

                form.render('select');
                laydate.render('cpdate')

                layer.open({
                    title: '编辑',
                    type: 1,
                    area: ["80%", "70%"],
                    content: $("#rccp")
                    , btn: '保存'
                    , btnAlign: 'c' //按钮居中
                    , shade: 0 //不显示遮罩
                    , cancel: function () {
                        $("#rccp").hide();
                    }, success: function () {

                        var valuetype = data.CpType;
                        if (valuetype == "锐途测评") {
                            $("#v5").show();
                            $("#v1").show();
                            document.getElementById("v1").value = data.CpResult;
                            $("#v2").hide();
                            $("#v3").hide();
                            $("#v4").hide();
                        } else if (valuetype == "管理人员外部招聘测评-中层通用" || valuetype == "管理人员外部招聘测评-销售" || valuetype == "管理人员外部招聘测评-财务" ||
                            valuetype == "管理人员外部招聘测评-人力资源" || valuetype == "管理人员外部招聘测评-行政" || valuetype == "管理人员评估选拔测评-中层通用" ||
                            valuetype == "管理人员评估选拔测评-销售" || valuetype == "管理人员评估选拔测评-财务" || valuetype == "管理人员评估选拔测评-人力资源" || valuetype == "管理人员评估选拔测评-行政") {
                            $("#v2").show();
                            document.getElementById("v2").value = data.CpResult;
                            $("#v5").show();
                            $("#v1").hide();
                            $("#v3").hide();
                            $("#v4").hide();
                        } else if (valuetype == "基层人员校园招聘-通用" || valuetype == "基层人员校园招聘-财务" || valuetype == "基层人员校园招聘-技术研发" || valuetype == "基层人员校园招聘-客户服务" ||
                            valuetype == "基层人员校园招聘-营销" || valuetype == "基层人员校园招聘-职能支持类" || valuetype == "基层人员社会招聘-财务类" || valuetype == "基层人员社会招聘-客户服务类" ||
                            valuetype == "基层人员社会招聘-销售类" || valuetype == "基层人员社会招聘-人力资源类" || valuetype == "基层人员社会招聘-行政类" || valuetype == "基层人员社会招聘-技术支持类" ||
                            valuetype == "基层潜才测评-通用高潜") {
                            $("#v3").show();
                            $("#v4").show();
                            $("#v1").hide();
                            $("#v2").hide();
                            $("#v5").hide();
                        } else {
                            $("#v1").hide();
                            $("#v2").hide();
                            $("#v3").hide();
                            $("#v4").hide();
                            $("#v5").hide();
                        }

                    },
                    yes: function (index) {
                        if (document.getElementById('CpFile').value == "" || document.getElementById('CpFile').value == null) {
                            document.getElementById('CpFile').value = "无附件";

                        }
                        $.ajax({
                            url: "/Rccps/Del_rccp",    //后台数据请求地址
                            type: "post",
                            async: false,
                            data: { "id": data.id },
                            success: function (resut) {
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                layer.close(index);
                            }
                        });
                        to();
                        UpRccp();
                        table.reload('testRccp', {
                            where: {
                                "Jbxxid": $("#jbxxid").val()
                            }
                        });

                        $("#rccp").hide();
                        layer.close(index);
                    }
                });           
            };
        });

    });

    //人才盘点保存
    layui.use('table', function () {

        table.render({
            elem: '#testRcpd'
            , url: '../Rcpd/ShowRcpd' + abc
            //, data: datarcpd
            , toolbar: '#toolbarRcpd'
            , cols: [[
                { field: 'DateTime', width: 120, title: '盘点时间', width: 125, minWidth: 125 }
                , { field: 'PdName', width: 100, title: '盘点项目', width: 125, minWidth: 125 }
                , {
                    field: 'PdResult', width: 180, title: '盘点结果', width: 460, minWidth: 460, templet: function (d) {
                        if (d.PdResult != null && d.PdResult != "" && d.PdResult != "[]") {
                            let str = [];

                            for (i = 0; i < d.PdResult.length; i++) {
                                if (d.PdResult[i] != "?") {
                                    str += d.PdResult[i];

                                } else {
                                    str += "\n";
                                }
                            }
                            return str;
                        }

                    }
                }
                , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#toolbarrcpd' }
            ]]
            , page: true
        });
        table.on('toolbar(testRcpd)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;  //获取选中行数据
                    layer.alert(JSON.stringify(data));
                    break;

                case 'addRcpdData':
                    var data = obj.data;
                    layer.open({

                        type: 1
                        , title: '人才盘点'
                        //具体配置参考：/docs/modules/layer.html#offset
                        , id: 'layerDemo'//防止重复弹出
                        , area: ["60%", "50%"]
                        , content: $("#rcpd"),//form 隐藏 display none

                        btn: '保存'
                        , btnAlign: 'c' //按钮居中
                        , shade: 0 //不显示遮罩
                        , yes: function () {

                            if ($(".pddate").val() == "") {
                                layer.msg("测评时间未填写");
                                return;
                            } else if ($("#pdxm").val() == "") {
                                layer.msg("盘点项目未填写");
                                return;
                            } else if ($("#pdjg").val() == "") {
                                layer.msg("盘点结果未填写");
                                return;
                            }

                            UpRcpd();
                            table.reload('testRcpd', {
                                where: {
                                    "Jbxxid": $("#jbxxid").val()
                                }
                            });
                            layer.closeAll();
                            layer.msg("保存成功");
                        }, 
                        cancel: function () {
                            $("#rcpd").hide()
                        },
                    })
                    break;
            };
        });
        table.on('tool(testRcpd)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del_rcpd') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: "/Rcpd/Del_rcpd",    //后台数据请求地址
                        type: "post",
                        async: false,
                        data: { "id": data.id },
                        success: function (resut) {
                            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            layer.close(index);
                            console.log(index);
                            layer.msg(resut);
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit_rcpd') {
                $(".pddate").val(data.DateTime);
                $('[name="PdName"]').val(data.PdName);
                $('[name="PdResult"]').val(data.PdResult);
                form.render('select');

                layer.open({
                    title: '编辑',
                    type: 1,
                    btn: "保存",
                    btnAlign: 'c',
                    area: ['60%', '50%'],
                    content: $("#rcpd"),
                    cancel: function () {
                        $("#rcpd").hide();
                    }, yes: function (layero, index) {

                        $.ajax({
                            url: "/Rcpd/Del_rcpd",    //后台数据请求地址
                            type: "post",
                            async: false,
                            data: { "id": data.id },
                            success: function (resut) {
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                layer.close(index);
                                console.log(index);
                                layer.msg(resut);
                            }
                        });

                        UpRcpd();
                        table.reload('testRcpd', {
                            where: {
                                "Jbxxid": $("#jbxxid").val()
                            }
                        });
                        layer.closeAll();
                        layer.msg("保存成功");
                        $("#rcpd").hide();
                    }
                });
            };
        });

    });

    function UpZlxx() {

        var text = $("#bjdc").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#bjdc").val(des);

        var text = $("#resultxc").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#resultxc").val(des);

        var data = [];
        var a = $('#zlxxform').serialize();
        var x = a + '&Jbxxid=' + $("#jbxxid").val();
        $.ajax({
            url: "/Zlxxes/Create",
            data: x,
            type: "post",
            async: false,
            success: function (resut) {
                data = resut;
                layer.msg("保存成功");

            }        
        });
        return data;
    };
    function UpRcpd() {

        var text = $("#pdjg").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#pdjg").val(des);

        var text = $("#pdxm").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#pdxm").val(des);

        var data = [];
        var a = $('#rcpd').serialize();
        var x = a + '&Jbxxid=' + $("#jbxxid").val();
        $.ajax({
            url: "/Rcpd/Create",
            data: x,
            type: "post",
            async: false,
            success: function (resut) {
                data = resut;
                layer.msg("保存成功");

            }
        });
        $("#rcpd").hide();
        return data;
    };
    function UpRccp() {

        var data = [];
        var a = $('#rccp').serialize();
        var x = a + '&Jbxxid=' + $("#jbxxid").val();
        $.ajax({
            url: "/Rccps/Create",
            data: x,
            type: "post",
            async: false,
            success: function (resut) {
                data = resut;
                $("#rccp").hide();
            }

        });
        $("#rccp").hide();

        return data;
    };

});

//显示与隐藏其他
layui.use('form', function () {
    var form = layui.form;
    //监听提交
    form.on('select(zp)', function (data) {
        var value = data.value;
        if (value == "关系推荐") {
            $("#qita").show();
            document.getElementById("")
        } else {
            $("#qita").hide();
        }
    });
    form.on('submit(formData)', function (data) {
        layer.msg(JSON.stringify(data.field));
        return false;
    });
});

//是否背景调查
layui.use('form', function () {
    var form = layui.form;

    form.on('radio(bjdc)', function (data) {

        if ($('#IsbjdcPurchased input[name="dc"]:checked ').val() == "否") {
            $("#yesbjdc").hide();
            $("textarea[name=Bjdc]").val("没有背景调查");
        }
        else {
            $("#yesbjdc").show();
            $("textarea[name=Bjdc]").val("背调人员：\n背调时间：\n背调情况：");
        }
        form.render();
    });
});

//测评类型
layui.use('form', function () {
    var form = layui.form;
    //var valuetype = document.getElementById("cptype").valueof();
    //var _value = $("#cptype").val();
    form.on('select(cptype)', function (data) {
        var valuetype = data.value;
        if (valuetype == "锐途测评") {
            $("#v5").show();
            $("#v1").show();
            $("#v2").hide();
            $("#v3").hide();
            $("#v4").hide();
        } else if (valuetype == "管理人员外部招聘测评-中层通用" || valuetype == "管理人员外部招聘测评-销售" || valuetype == "管理人员外部招聘测评-财务" ||
            valuetype == "管理人员外部招聘测评-人力资源" || valuetype == "管理人员外部招聘测评-行政" || valuetype == "管理人员评估选拔测评-中层通用" ||
            valuetype == "管理人员评估选拔测评-销售" || valuetype == "管理人员评估选拔测评-财务" || valuetype == "管理人员评估选拔测评-人力资源" || valuetype == "管理人员评估选拔测评-行政") {
            $("#v2").show();
            $("#v5").show();
            $("#v1").hide();
            $("#v3").hide();
            $("#v4").hide();
        } else if (valuetype == "基层人员校园招聘-通用" || valuetype == "基层人员校园招聘-财务" || valuetype == "基层人员校园招聘-技术研发" || valuetype == "基层人员校园招聘-客户服务" ||
            valuetype == "基层人员校园招聘-营销" || valuetype == "基层人员校园招聘-职能支持类" || valuetype == "基层人员社会招聘-财务类" || valuetype == "基层人员社会招聘-客户服务类" ||
            valuetype == "基层人员社会招聘-销售类" || valuetype == "基层人员社会招聘-人力资源类" || valuetype == "基层人员社会招聘-行政类" || valuetype == "基层人员社会招聘-技术支持类" ||
            valuetype == "基层潜才测评-通用高潜") {
            $("#v3").show();
            $("#v4").show();
            $("#v1").hide();
            $("#v2").hide();
            $("#v5").hide();
        } else {
            $("#v1").hide();
            $("#v2").hide();
            $("#v3").hide();
            $("#v4").hide();
            $("#v5").hide();
        }
    });
    form.on('submit(formData)', function (data) {
        layer.msg(JSON.stringify(data.field));
        return false;
    });
});

function to() {

    if (document.getElementById("cptype").value == "锐途测评") {
        var a = document.getElementById('value1').value;
        var e = document.getElementById('value5').value;
        //var a = $("#value1").val();
        //var e = $("#value5").val();

        document.getElementById('allvalue').value = e + "\n" + a;

        var text = $("#allvalue").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#allvalue").val(des);

    } else if (document.getElementById("cptype").value == "管理人员外部招聘测评-中层通用" || document.getElementById("cptype").value == "管理人员外部招聘测评-销售" || document.getElementById("cptype").value == "管理人员外部招聘测评-财务" ||
        document.getElementById("cptype").value == "管理人员外部招聘测评-人力资源" || document.getElementById("cptype").value == "管理人员外部招聘测评-行政" || document.getElementById("cptype").value == "管理人员评估选拔测评-中层通用" ||
        document.getElementById("cptype").value == "管理人员评估选拔测评-销售" || document.getElementById("cptype").value == "管理人员评估选拔测评-财务" || document.getElementById("cptype").value == "管理人员评估选拔测评-人力资源" || document.getElementById("cptype").value == "管理人员评估选拔测评-行政") {
        var b = document.getElementById('value2').value;
        var e = document.getElementById('value5').value;

        document.getElementById('allvalue').value = e + "\n" + b;
        var text = $("#allvalue").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#allvalue").val(des);

    } else if (document.getElementById("cptype").value == "基层人员校园招聘-通用" || document.getElementById("cptype").value == "基层人员校园招聘-财务" || document.getElementById("cptype").value == "基层人员校园招聘-技术研发" || document.getElementById("cptype").value == "基层人员校园招聘-客户服务" ||
        document.getElementById("cptype").value == "基层人员校园招聘-营销" || document.getElementById("cptype").value == "基层人员校园招聘-职能支持类" || document.getElementById("cptype").value == "基层人员社会招聘-财务类" || document.getElementById("cptype").value == "基层人员社会招聘-客户服务类" ||
        document.getElementById("cptype").value == "基层人员社会招聘-销售类" || document.getElementById("cptype").value == "基层人员社会招聘-人力资源类" || document.getElementById("cptype").value == "基层人员社会招聘-行政类" || document.getElementById("cptype").value == "基层人员社会招聘-技术支持类" ||
        document.getElementById("cptype").value == "基层潜才测评-通用高潜") {
        var c = document.getElementById('value3').value;
        var d = document.getElementById('value4').value;

        document.getElementById('allvalue').value = d + "\n" + c;
        var text = $("#allvalue").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#allvalue").val(des);
    } else if (document.getElementById("cptype").value == "高层领导力测评") {
        document.getElementById("allvalue").value = "高层领导力测评";
    } else if (document.getElementById("cptype").value == "360测评") {
        document.getElementById("allvalue").value = "360测评";
    }
}

function gettheUserldatas() {

    var lis = [];

    $.ajax({
        url: "/User/GetUserData",
        type: "post",
        async: false,
        success: function (datas) {

            lis = datas;
            console.log(lis);

        }
    })

    return lis;

}
   
function Del_rccp(id) {
    var data = form.val('rccp');
    $.ajax({
        url: "/Rccps/Del_rccp",    //后台数据请求地址
        type: "post",
        async: false,
        data: { "id": id },
        success: function (resut) {
            layer.msg(resut);
        }
    });
    return data;
}
function Del_rcpd(id) {
    var data = form.val('rcpd');
    $.ajax({
        url: "/Rcpd/Del_rcpd",    //后台数据请求地址
        type: "post",
        async: false,
        data: { "id": id },
        success: function (resut) {
            layer.msg(resut);
        }
    });
    return data;
}

function proofPicturercdjb(d) {
    var i, count = 0;
    var str = [], aaa = [];
    var proofPicture = d.rcdjb;
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = d.rcdjb.split(",");
        for (i = 0; i < d.rcdjb.length; i++) {
            if (d.rcdjb[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }

        return aaa;
    }
}
function proofPicturemsb(d) {
    var i, count = 0;
    var str = [], aaa = [];
    var proofPicture = d.msb;
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = d.msb.split(",");
        for (i = 0; i < d.msb.length; i++) {
            if (d.msb[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }
        
        return aaa;
    }
}
function proofPicturebz(d) {
    var proofPicture = d.resultBz;
    var i, count = 0;
    var str = [], aaa = [];
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = proofPicture.split(",");
        for (i = 0; i < proofPicture.length; i++) {
            if (proofPicture[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }

        return aaa;
    }
}
function proofPicturecp(d) {
    var proofPicture = d.CpFile;
    var i, count = 0;
    var str = [], aaa = [];
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = proofPicture.split(",");
        for (i = 0; i < proofPicture.length; i++) {
            if (proofPicture[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }

        return aaa;
    }
}